import "@/styles/globals.css"
import { Metadata } from "next"
import Script from "next/script"

import { siteConfig } from "@/config/site"
import { fontSans } from "@/lib/fonts"
import { cn } from "@/lib/utils"
import { ThemeProvider } from "@/components/theme-provider"
import { Toaster } from "@/components/ui/toaster"
import { DialogProvider } from "@/contexts/dialog-context"
import { StructuredData } from "@/components/structured-data"

export const metadata: Metadata = {
  title: {
    default: siteConfig.name,
    template: `%s - ${siteConfig.name}`
  },
  description: siteConfig.description,
  keywords: [
    "导航网站",
    "网址导航", 
    "Hello123",
    "在线导航",
    "网站收藏",
    "常用网站",
    "AI工具导航",
    "搜索引擎导航",
    "开发者工具",
    "设计工具",
    "实用工具"
  ],
  authors: [{ name: "Hello123导航" }],
  creator: "Hello123导航",
  publisher: "Hello123导航",
  formatDetection: {
    email: false,
    address: false,
    telephone: false,
  },
  // SEO优化
  robots: {
    index: true,
    follow: true,
    googleBot: {
      index: true,
      follow: true,
      'max-video-preview': -1,
      'max-image-preview': 'large',
      'max-snippet': -1,
    },
  },
  // Open Graph (Facebook, LinkedIn等社交媒体)
  openGraph: {
    type: 'website',
    locale: 'zh_CN',
    url: 'https://mini.hello123.com',
    title: siteConfig.name,
    description: siteConfig.description,
    siteName: siteConfig.name,
    images: [
      {
        url: '/hello123.png',
        width: 1200,
        height: 630,
        alt: 'Hello123导航 - 上网不迷路',
      }
    ],
  },
  // Twitter Cards
  twitter: {
    card: 'summary_large_image',
    title: siteConfig.name,
    description: siteConfig.description,
    images: ['/hello123.png'],
    creator: '@hello123nav',
  },
  // PWA相关
  applicationName: siteConfig.name,
  appleWebApp: {
    capable: true,
    statusBarStyle: 'default',
    title: siteConfig.name,
  },
  // 网站验证
  verification: {
    google: 'your-google-verification-code',
    yandex: 'your-yandex-verification-code',
    yahoo: 'your-yahoo-verification-code',
  },
  // Google AdSense 配置
  other: {
    "google-adsense-account": "ca-pub-4712732405232789"
  }
}

interface RootLayoutProps {
  children: React.ReactNode
}

export default function RootLayout({ children }: RootLayoutProps) {
  return (
    <>
      <html lang="zh-CN" suppressHydrationWarning>
        <head>
          <meta name="viewport" content="width=device-width, initial-scale=1" />
          <link rel="canonical" href="https://mini.hello123.com" />
          <link rel="icon" href="/favicon.ico" />
          <link rel="apple-touch-icon" href="/hello123.png" />
          {process.env.NODE_ENV === "production" && (
            <>
              <Script id="baidu-hmt-init" strategy="beforeInteractive">
                {`window._hmt = window._hmt || [];`}
              </Script>
              <Script
                id="baidu-hmt"
                strategy="afterInteractive"
                src="https://hm.baidu.com/hm.js?516c88b1db21c474fced03f36dfd60c8"
              />
            </>
          )}
          {/* 结构化数据 - 帮助搜索引擎理解网站内容 */}
          <StructuredData />
        </head>
        <body className={cn("min-h-screen bg-background font-sans antialiased", fontSans.variable)}>
          <ThemeProvider attribute="class" defaultTheme="system" enableSystem>
            <DialogProvider>
              {children}
              <Toaster />
            </DialogProvider>
          </ThemeProvider>
        </body>
      </html>
    </>
  )
}
